package com.ybkj.o2o.mc.common.query;

import org.apache.commons.lang.StringUtils;

import java.io.Serializable;
import java.util.Date;

/**
 * Created by shine on 16/9/20.
 */
public class EnterpriseQuery implements Serializable {

  private Long[] gradeIds;

  private Long companyId;

  private String companyName;

  private Date startTime;

  private Date endTime;

  private String name;

  private String address;

  private String keyword;

  private String appKey;

  private Integer page;

  private Integer rows;

  private Integer offset;

  public Long[] getGradeIds() {
    return gradeIds;
  }

  public void setGradeIds(Long[] gradeIds) {
    this.gradeIds = gradeIds;
  }

  public Long getCompanyId() {
    return companyId;
  }

  public void setCompanyId(Long companyId) {
    this.companyId = companyId;
  }

  public String getCompanyName() {

    return companyName;
  }

  /**
   * 普通字符串转换为数据库模糊查询的字符串，即两边连接'%'.
   */
  public void setCompanyName(String companyName) {
    if (StringUtils.isNotBlank(companyName)) {
      this.companyName = "%" + companyName + "%";
    } else {
      this.companyName = null;
    }

  }

  public Date getStartTime() {
    return startTime;
  }

  /**
   * 把long转换为date类型.
   */
  public void setStartTime(Long start) {
    if (null != start) {
      this.startTime = new Date(start);
    }
  }

  public Date getEndTime() {
    return endTime;
  }

  /**
   * 把long转换为date类型.
   */
  public void setEndTime(Long end) {
    if (null != end) {
      this.endTime = new Date(end);
    }
  }

  public String getName() {

    return name;
  }

  /**
   * 普通字符串转换为数据库模糊查询的字符串，即两边连接'%'.
   */
  public void setName(String name) {
    if (StringUtils.isNotBlank(name)) {
      this.name = "%" + name + "%";
    } else {
      this.name = null;
    }
  }

  public String getAddress() {

    return address;
  }

  /**
   * 普通字符串转换为数据库模糊查询的字符串，即两边连接'%'.
   */
  public void setAddress(String address) {
    if (StringUtils.isNotBlank(address)) {
      this.address = "%" + address + "%";
    } else {
      this.address = null;
    }
  }

  public String getKeyword() {

    return keyword;
  }

  /**
   * 普通字符串转换为数据库模糊查询的字符串，即两边连接'%'.
   */
  public void setKeyword(String keyword) {
    if (StringUtils.isNotBlank(keyword)) {
      this.keyword = "%" + keyword + "%";
    } else {
      this.keyword = null;
    }
  }

  public String getAppKey() {
    return appKey;
  }

  public void setAppKey(String appKey) {
    this.appKey = appKey;
  }

  public Integer getPage() {
    return page;
  }

  public void setPage(Integer page) {
    this.page = page;
  }

  public Integer getRows() {
    return rows;
  }

  public void setRows(Integer rows) {
    this.rows = rows;
  }

  /**
   * 根据page和rows计算出偏移量.
   */
  public Integer getOffset() {
    if (null != getPage() && getPage() > 0) {
      return (getPage() - 1) * getRows();
    }
    return offset;
  }

  public void setOffset(Integer offset) {
    this.offset = offset;
  }
}
